package org.jeecg.modules.project.util;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.domain.AlipayDataDataserviceXlightTaskQueryModel;
import com.alipay.api.response.AlipayDataDataserviceXlightTaskQueryResponse;
import com.alipay.api.request.AlipayDataDataserviceXlightTaskQueryRequest;

/**
 * @author Mr.Liu
 * @date 2024/05/15
 * @Description 任务广告完成状态查询
 */
public class AlipayDataDataserviceXlightTaskQuery {

    public static void main(String[] args) throws AlipayApiException {
        // 初始化SDK
        AlipayClient alipayClient = new DefaultAlipayClient(getAlipayConfig());

        // 构造请求参数以调用接口
        AlipayDataDataserviceXlightTaskQueryRequest request = new AlipayDataDataserviceXlightTaskQueryRequest();
        AlipayDataDataserviceXlightTaskQueryModel model = new AlipayDataDataserviceXlightTaskQueryModel();

        // uid参数未来计划废弃，存量商户可继续使用，新商户请使用openid。请根据应用-开发配置-openid配置选择支持的字段。
        // model.setUserId("208840255xxxxxxx");

        // 设置支付宝用户在应用维度下的唯一id
        model.setOpenId("074a1CcTG1LelxKe4xQC0zgNdId0nxi95b5lsNpazWYoCo5");

        // 设置任务流水号
        model.setBizId("be2867fb8a2ab72ae4a2e07344099c8f");

        request.setBizModel(model);
        AlipayDataDataserviceXlightTaskQueryResponse response = alipayClient.execute(request);
        System.out.println(response.getBody());

        if (response.isSuccess()) {
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
            // sdk版本是"4.38.0.ALL"及以上,可以参考下面的示例获取诊断链接
            // String diagnosisUrl = DiagnosisUtils.getDiagnosisUrl(response);
            // System.out.println(diagnosisUrl);
        }
    }

    private static AlipayConfig getAlipayConfig() {
        String privateKey = "<-- 请填写您的应用私钥，例如：MIIEvQIBADANB ... ... -->";
        String alipayPublicKey = "<-- 请填写您的支付宝公钥，例如：MIIBIjANBg... -->";
        AlipayConfig alipayConfig = new AlipayConfig();
        alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do");
        alipayConfig.setAppId("<-- 请填写您的AppId，例如：2019091767145019 -->");
        alipayConfig.setPrivateKey(privateKey);
        alipayConfig.setFormat("json");
        alipayConfig.setAlipayPublicKey(alipayPublicKey);
        alipayConfig.setCharset("UTF-8");
        alipayConfig.setSignType("RSA2");
        return alipayConfig;
    }

}
